<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>案例</title>
</head>
<body>
<input type="button" value="开灯" onclick="on()">
<img src="../imgs/off.gif" id="myImge" style="text-align: center">
<input type="button" value="关灯" onclick="off()">
<script>
function on(){
    document.getElementById('myImge').src="../imgs/on.gif";
}

function off(){
    document.getElementById('myImge').src="../imgs/off.gif";
}
var num=1;
setInterval(function (){
    if(num%2==0){
        on();
    }
    else {
        off();
    }
    num++;
},300)

</script>
</body>
</html>